package com.erclab.xpresso.formelements
{
	import mx.controls.TextArea;
	
	import mx.controls.Label;
	import mx.core.UIComponent;
	import mx.containers.FormItem;

	public class TextArea extends mx.containers.FormItem implements FormElement
	{
		protected var textArea:mx.controls.TextArea;
		protected var destinationColumn:String;

		public function TextArea():void{
			textArea = new mx.controls.TextArea();
			this.addChild(textArea);
		}	
		
		public function getValue():String
		{
			return String(this.textArea.text);
		}
		
		public function getName():String
		{
			return String(this.name);
		}
		
		public function createLabel(attachingElement:UIComponent, label:String):void{
			this.label = label;
		}
		
		
		public function setValue(value:String):void {
			if (value != null){
				while (value.indexOf("<") > -1){
					value = value.replace("<", "&lt;");
					value = value.replace(">", "&gt;");
				}
				this.textArea.htmlText = value; 
			}
		}
		
		public function getAttribute(attribute:String):String{
			if (attribute.indexOf("e.") == 0){
				return this.textArea[attribute.substr(2, attribute.length)];
			} else {
				return this[attribute];
			}
		}
		
		public function setAttribute(attribute:String, attributeValue:String):void{
			if (attribute.indexOf("e.") == 0){
				this.textArea[attribute.substr(2, attribute.length)] = attributeValue;
			} else {
				this[attribute] = attributeValue;
			}
		}

		public function prepareForInsert():void{
			this.textArea.text = "";
		}

	}		
}